package net.scdx.hotel.service.impl;

import net.scdx.hotel.dto.AdminExecution;
import net.scdx.hotel.entity.Admin;
import net.scdx.hotel.mapper.AdminMapper;
import net.scdx.hotel.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public AdminExecution adminLogin(String username, String password) throws Exception {
        boolean success = true;
        String msg = "";

        if (username == null || password == null || username.trim() == "" || password.trim() == "")
            return new AdminExecution(false, "username or password is empty", null);

        // query user
        Admin admin = adminMapper.queryUserByUsernameOrPsw(username, password);
        if (admin == null) {
            success = false;
            msg = "username or password is wrong";
        }

        return new AdminExecution(success, msg, admin);
    }
}
